//
//  AppData.m
//  projectBase
//
//  Created by zhuangzhh on 14-11-16.
//  Copyright (c) 2014年 zhuangzhh. All rights reserved.
//

#import "AppData.h"



@implementation AppData

static AppData* mInstance;

+ (AppData*)shareInstance
{
    if (nil == mInstance)
    {
        mInstance = [[AppData alloc] init];
    }
    
    return mInstance;
}

-(id)init
{
    self = [super init];
    if(self != nil)
    {
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        self.version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        self.loginmidarray = [NSMutableArray array];
    }
    
    return self;
}

+(NSString *)getpersonshopmid
{
    
    NSArray *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *docPath = [ doc objectAtIndex:0 ];
    
    if( [[NSFileManager defaultManager] fileExistsAtPath:[docPath stringByAppendingPathComponent:@"personshop.plist"] ]==NO ) {
        
        NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"personshop" ofType:@"plist"];
        NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:plistPath];
        NSLog(@"%@", data);//直接打印数据
        //得到完整的文件名
        NSString *filename=[docPath stringByAppendingPathComponent:@"personshop.plist"];
        [data writeToFile:filename atomically:YES];
        return [NSString stringWithFormat:@"%@",[data objectForKey:@"mid"]];
    }
    else
    {
        //得到完整的文件名
        NSString *filename=[docPath stringByAppendingPathComponent:@"personshop.plist"];
        NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
        [data writeToFile:filename atomically:YES];
        return [NSString stringWithFormat:@"%@",[data objectForKey:@"mid"]];

    }
    return nil;
}

+(void)setpersonshopmid:(NSString *)mid
{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *plistPath1 = [paths objectAtIndex:0];
    NSString *filename=[plistPath1 stringByAppendingPathComponent:@"personshop.plist"];
    //输入写入
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
    [data setObject:mid forKey:@"mid"];

    [data writeToFile:filename atomically:YES];
    //那怎么证明我的数据写入了呢？读出来看看
    NSMutableDictionary *data1 = [[NSMutableDictionary alloc] initWithContentsOfFile:filename];
    NSLog(@"%@", data1);
}

@end
